import { getToken } from '@/utils/token'
import { defineStore } from 'pinia'

const Cards = {}
const useAppStore = defineStore('app', {
    state: () => {
        return {
            isShowConsole: false,
            sendMsg: 'test',
            reviceMsg: 'test',
            isLogin: false || !!getToken(), //是否登录
            loginParams: {},
            showPanel: true, //是否显示数据面板
            showZjPanel: false, // 是否显示闸机数据
            zjID: '', //
            isNewPush: false, //是否新添加数据
            // 
            zjUserList: [], //
            zjCarList: [], 


            // 场馆用户按区域分类数据
            areaListObj: {

            },
        }
    },
    actions: {
        setConsoleStatus(bool) {
            this.isShowConsole = bool
        },
        setLoginStatus(bool) {
            this.isLogin = bool;
        },
        setLoginParams(info) {
            this.loginParams = info;
        },
        // 是否显示闸机模块
        setZjPanel(bool) {
            this.showZjPanel = bool;
        },
        setZjId(id) {
            this.zjID = id;
        },

        setAreaListData(list) {
            const obj = {}
            list.map(item => {
                if (item.area) {
                    if (!obj[item.area]) {
                        obj[item.area] = []
                    }
                    obj[item.area].push(item);
                }
            })

            this.areaListObj = obj;
        },

        pushPassData(list) {
            const list1 = []
            const list2 = []
            list.map(item => {
                // if (!Cards[item.rfno]) {
                //     Cards[item.rfno] = 1;
                if (item.type === 1) {
                    list1.push(item)
                } else {
                    list2.push(item)
                }
                // }
            })
            this.zjUserList = list1
            this.zjCarList = list2
            // console.log(' this.zjUserList',  this.zjUserList)
            // console.log(' this.zjCarList',  this.zjCarList)
        },
        // 是否显示数据面板
        setShowPanel(bool) {
            this.showPanel = bool;
        },
        setSendMsg(msg) {
            this.sendMsg = msg;
        },
        setReviceMsg(msg) {
            this.reviceMsg = msg;
        }
    },
    persist: true,
})

export default useAppStore;